﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Student;
using RegisterationCommon.Common;
using System.Data;
namespace RegisterationSystem.Space_Student
{
    public partial class loginpswdupdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!StudentInfo.Current.IsLogin())
                {
                    Message.Send(10001);
                }
                string sql = "select * from " + ETableName.Students + " where IDCardNumber='" + CookiesInfo.GetValue("Robo", "IDCardNumber") + "' and LoginPswd='" + CookiesInfo.GetValue("Robo", "LoginPswd") + "'";
                DataTable dt = DBAction.GetDTFromSQL(sql);
                if (dt.Rows.Count > 0)
                {
                    lblname.Text = Convert.ToString(dt.Rows[0]["TrueName"]);//学生名称
                }
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string ymm = this.OldAccountPswd.Value;
            string xmm = this.NewAccountPswd.Value;
            //判断原密码是否正确
            if (BaseLibrary.ConvertToMD5(ymm.ToLower()) !=CookiesInfo.GetValue("Robo", "LoginPswd"))
            {
                this.cpJS2.Text = "<script>alert('原密码错误!')</script>";
            }
            else
            {
                StudentInfo.Current.LoginPswd = BaseLibrary.ConvertToMD5(xmm.ToLower());
                if (StudentInfo.Current.MdfAccountPwd())
                {
                    //修改成功
                    this.cpJS2.Text = "<script>alert('密码修改成功，请重新登录!');window.location='login.aspx'</script>";
                }
                else
                {
                    //修改失败
                    this.cpJS2.Text = "<script>alert('修改失败!')</script>";
                }
            }
        }
    }
}